package com.study.spmongodb.book.wwj.char05;

import java.util.concurrent.TimeUnit;

/**
 * @author MI
 * @version 1.0
 * @date 2020/11/25 21:35
 */
public class ThreadGroupEnumerateThreads {
    public static void main(String[] args) throws InterruptedException {

        //创建一个ThreadGroup
        final ThreadGroup myGroup = new ThreadGroup("MyGroup");
        final Thread thread = new Thread(() -> {
            while (true) {
                try {
                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }, "MyThread");
        thread.start();

        TimeUnit.MILLISECONDS.sleep(2);
        final ThreadGroup mainGroup = Thread.currentThread().getThreadGroup();

        final Thread[] list = new Thread[mainGroup.activeCount()];
        int enumerate = mainGroup.enumerate(list);
        System.out.println(enumerate);
        enumerate = mainGroup.enumerate(list, false);

        System.out.println(enumerate);
    }
}
